package com.quartet.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Bean
    public AuthInterceptor authInterceptor() {
        return new AuthInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器要声明拦截器对象和要拦截的请求
        registry.addInterceptor(new AuthInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/**/login/**")
                .excludePathPatterns("/**/logout/**")
                .excludePathPatterns("/api/**")
                .excludePathPatterns("/tPlatformStatistics/queryPlatformStatisticsData")
                .excludePathPatterns("/tPlatformStatistics/queryPlatformStatisticsInsertData")
                .excludePathPatterns("/tPlatformStatistics/queryPlatformStatisticsInsertChartData")
                .excludePathPatterns("/tTerminalAlarmInfo/selectTerminalRealAlarmCount")
                .excludePathPatterns("/tTerminalInfo/queryCustomerCodeByTerminalCode")
                .excludePathPatterns("/tTerminalStock/updateTerminalStockStatus")
                .excludePathPatterns("/file/sendCommand")
                .excludePathPatterns("/file/selectMediaPageByTerminalCode")
                .excludePathPatterns("/tServiceInfo/queryMapNameListByCustomerCode")
                .excludePathPatterns("/tServiceInfo/queryMapJson")
                .excludePathPatterns("/tOrder/sendEmail")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**","/csrf","/error","/");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations(
                "classpath:/static/");
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}